#include <iostream>
#include <string>

using std::cout;
using std::endl;
using std::string;

int gNum = 100;

class Example
{
    void operator()(int value) const
    {
        cout << "num = " << num << endl;
        cout << "age = " << age << endl;
    }

    int num;
    int &age;
};
void test()
{
    int num = 10;
    int age = 60;
    string name("wangdao");

    auto f = [num, &age](int value){
        cout << "value = " << value << endl;
        cout << "num = " << num << endl;
        age += 10;
        cout << "age = " << age << endl;
        cout << "gNum = " << gNum << endl;
    };

    f(200);

    cout << endl << endl;
    auto f2 = [&num, &age, name](int value){
        num += 10;
        age += 10;
        cout << "value = " << value << endl;
        cout << "num = " << num << endl;
        cout << "age = " << age << endl;
        cout << "name = " << name << endl;
    };
    f2(200);

    cout << endl << endl;
    auto f3 = [&, name](int value){
        num += 10;
        age += 10;
        cout << "value = " << value << endl;
        cout << "num = " << num << endl;
        cout << "age = " << age << endl;
        cout << "name = " << name << endl;
    };
    f3(300);

    cout << endl << endl;
    auto f4 = [=, &age](int value){
        age += 10;
        cout << "value = " << value << endl;
        cout << "num = " << num << endl;
        cout << "age = " << age << endl;
        cout << "name = " << name << endl;
    };
    f4(400);
}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

